#include <QApplication>
#include "ElaApplication.h"
#include "ElaTheme.h"
#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QDebug>

#include "ElaWidget.h"
#include "ElaMessageButton.h"

class SimpleTest : public ElaWidget
{
    Q_OBJECT

public:
    SimpleTest(QWidget *parent = nullptr) : ElaWidget(parent)
    {
        setupUI();
    }

private:
    void setupUI()
    {
        QVBoxLayout *mainLayout = new QVBoxLayout(this);
        
        // 标题
        QLabel *titleLabel = new QLabel("ElaMessageButton 简单示例", this);
        titleLabel->setAlignment(Qt::AlignCenter);
        QFont titleFont = titleLabel->font();
        titleFont.setPointSize(16);
        titleFont.setBold(true);
        titleLabel->setFont(titleFont);
        
        // 创建消息按钮
        ElaMessageButton *successBtn = new ElaMessageButton("成功示例", this);
        ElaMessageButton *errorBtn = new ElaMessageButton("错误示例", this);
        ElaMessageButton *warningBtn = new ElaMessageButton("警告示例", this);
        ElaMessageButton *infoBtn = new ElaMessageButton("信息示例", this);
        
        // 配置成功按钮
        successBtn->setBarTitle("操作成功");
        successBtn->setBarText("数据保存成功！");
        successBtn->setMessageMode(ElaMessageBarType::Success);
        successBtn->setDisplayMsec(3000);
        
        // 配置错误按钮
        errorBtn->setBarTitle("发生错误");
        errorBtn->setBarText("无法连接到服务器，请检查网络设置。");
        errorBtn->setMessageMode(ElaMessageBarType::Error);
        errorBtn->setDisplayMsec(4000);
        
        // 配置警告按钮
        warningBtn->setBarTitle("系统警告");
        warningBtn->setBarText("磁盘空间不足，建议清理临时文件。");
        warningBtn->setMessageMode(ElaMessageBarType::Warning);
        warningBtn->setDisplayMsec(3500);
        
        // 配置信息按钮
        infoBtn->setBarTitle("系统通知");
        infoBtn->setBarText("新版本 v2.0.0 已发布，点击查看更新内容。");
        infoBtn->setMessageMode(ElaMessageBarType::Information);
        infoBtn->setDisplayMsec(2500);
        
        // 按钮布局
        QHBoxLayout *btnLayout1 = new QHBoxLayout();
        btnLayout1->addWidget(successBtn);
        btnLayout1->addWidget(errorBtn);
        
        QHBoxLayout *btnLayout2 = new QHBoxLayout();
        btnLayout2->addWidget(warningBtn);
        btnLayout2->addWidget(infoBtn);
        
        // 添加到主布局
        mainLayout->addWidget(titleLabel);
        mainLayout->addSpacing(20);
        mainLayout->addLayout(btnLayout1);
        mainLayout->addLayout(btnLayout2);
        mainLayout->addStretch();
        
        // 连接信号（可选）
        connect(successBtn, &ElaMessageButton::clicked, []() {
            qDebug() << "成功按钮被点击";
        });
        
        connect(errorBtn, &ElaMessageButton::clicked, []() {
            qDebug() << "错误按钮被点击";
        });
        
        connect(warningBtn, &ElaMessageButton::clicked, []() {
            qDebug() << "警告按钮被点击";
        });
        
        connect(infoBtn, &ElaMessageButton::clicked, []() {
            qDebug() << "信息按钮被点击";
        });
    }
};

int main(int argc, char *argv[])
{
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
    QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
    QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#else
    qputenv("QT_SCALE_FACTOR", "1.5");
#endif
#endif

    QApplication app(argc, argv);

    // 确保应用程序和主题系统正确初始化
    eApp->init();

    SimpleTest window;
    window.setWindowTitle("简单消息按钮示例");
    window.resize(500, 300);
    window.moveToCenter();
    window.show();

    return app.exec();
}


#include "ElaMessage_simple.moc"



